export const userState = defineStore('user',{
    // 定义状态
    state: () => ({
        uuid: "",
        username: "",
        avatar: "",
        msgcount:0
    }),

    // 修改状态
    actions: {
        // 用户登录
        setLoginUserInfo(user){
            this.uuid = user.uuid
            this.username = user.username
            this.avatar = user.avatar
            this.msgcount = user.msgcount
        }
    },

    // 获取状态
    getters:{
        isLogin(){
            return this.uuid != ""
        }
    },

    // persist定义要做判断，因为localStorage是客户端参数，所以需要加process.client
    persist: process.client && {
        storage: localStorage, // sessionStorage
        key: "kong-nuxt-userLogin"
    }
})
